{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19",
    "_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/kaggle/input/ieee-cis-12nd-solution-part-3-cat/__results__.html\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-3-cat/custom.css\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-3-cat/cat_train.csv\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-3-cat/cat.csv\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-3-cat/__notebook__.ipynb\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-3-cat/__output__.json\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-3-cat/__resultx__.html\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-3-cat/catboost_info/catboost_training.json\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-3-cat/catboost_info/test_error.tsv\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-3-cat/catboost_info/time_left.tsv\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-3-cat/catboost_info/learn_error.tsv\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-3-cat/catboost_info/test/events.out.tfevents\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-3-cat/catboost_info/learn/events.out.tfevents\n",
      "/kaggle/input/ieee-fraud-detection/test_identity.csv\n",
      "/kaggle/input/ieee-fraud-detection/train_transaction.csv\n",
      "/kaggle/input/ieee-fraud-detection/sample_submission.csv\n",
      "/kaggle/input/ieee-fraud-detection/test_transaction.csv\n",
      "/kaggle/input/ieee-fraud-detection/train_identity.csv\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-4-xgb/__results__.html\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-4-xgb/xgb.csv\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-4-xgb/xgb_train.csv\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-4-xgb/custom.css\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-4-xgb/__notebook__.ipynb\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-4-xgb/__output__.json\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-4-xgb/__resultx__.html\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-2-lgb/__results__.html\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-2-lgb/custom.css\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-2-lgb/__notebook__.ipynb\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-2-lgb/__output__.json\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-2-lgb/lgb.csv\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-2-lgb/lgb_train.csv\n"
     ]
    }
   ],
   "source": [
    "# This Python 3 environment comes with many helpful analytics libraries installed\n",
    "# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n",
    "# For example, here's several helpful packages to load in \n",
    "\n",
    "import numpy as np # linear algebra\n",
    "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
    "\n",
    "# Input data files are available in the \"../input/\" directory.\n",
    "# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n",
    "\n",
    "import os\n",
    "for dirname, _, filenames in os.walk('/kaggle/input'):\n",
    "    for filename in filenames:\n",
    "        print(os.path.join(dirname, filename))\n",
    "\n",
    "# Any results you write to the current directory are saved as output."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "_cell_guid": "79c7e3d0-c299-4dcb-8224-4455121ee9b0",
    "_uuid": "d629ff2d2480ee46fbb7e2d37f6b5fab8052498a"
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.metrics import roc_auc_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_train = train_transaction = pd.read_csv('/kaggle/input/ieee-fraud-detection/train_transaction.csv',usecols = ['isFraud'])\n",
    "y_train = y_train.isFraud"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "lgb = pd.read_csv('/kaggle/input/ieee-cis-12nd-solution-part-2-lgb/lgb.csv')\n",
    "lgb_train = pd.read_csv('/kaggle/input/ieee-cis-12nd-solution-part-2-lgb/lgb_train.csv')\n",
    "xgb = pd.read_csv('/kaggle/input/ieee-cis-12nd-solution-part-4-xgb/xgb.csv')\n",
    "xgb_train = pd.read_csv('/kaggle/input/ieee-cis-12nd-solution-part-4-xgb/xgb_train.csv')\n",
    "cat = pd.read_csv('/kaggle/input/ieee-cis-12nd-solution-part-3-cat/cat.csv')\n",
    "cat_train = pd.read_csv('/kaggle/input/ieee-cis-12nd-solution-part-3-cat/cat_train.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1.        , 0.99528438, 0.92901527],\n",
       "       [0.99528438, 1.        , 0.93148535],\n",
       "       [0.92901527, 0.93148535, 1.        ]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 先构造一个矩阵\n",
    "df = np.array([lgb.isFraud, xgb.isFraud, cat.isFraud])\n",
    "# 计算协方差矩阵\n",
    "np.corrcoef(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9550520141936576\n",
      "0.9525709411706289\n",
      "0.9595312371767415\n"
     ]
    }
   ],
   "source": [
    "print(roc_auc_score(y_train.values,lgb_train.train.values))\n",
    "print(roc_auc_score(y_train.values,xgb_train.train.values))\n",
    "print(roc_auc_score(y_train.values,cat_train.train.values))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "由于kernal notebook的机能限制我们这里的catboost仅使用了0.1的学习率，如果使用0.05的学习率，会有更高的成绩"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "                cv       public  private\n",
    "            lbg 95505    96095   93860\n",
    "            XGB 95257    96000   93509\n",
    "            cat 95953    95858   93302  \n",
    "    0.9*lgb + 0.1*xgb =  96099   93839\n",
    "    0.9*lgb + 0.1*cat =  96292   94113      \n",
    "    0.8*lgb + 0.2*cat =  96321   94119        <-- this is our bst score . \n",
    "                                         if lr of catboost is 0.005,private score could be 9415\n",
    "    0.7*lgb + 0.3*cat =  96314   94082"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "sub = lgb.copy()\n",
    "sub.isFraud = 0.8*lgb.isFraud + 0.2*cat.isFraud\n",
    "sub.to_csv('./sub.csv',index = None)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
